<?php
// +----------------------------------------------------------------------
// | 登录验证中间件
// +----------------------------------------------------------------------
// | Author: myh
// +----------------------------------------------------------------------
namespace app\pc\middleware;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class Auth
{
    public function handle($request, \Closure $next)
    {
        try{
            $token = $request->header('token');
            $device = $request->header('device');

            if($device == 'pc' && $token){
                JWT::decode($token,new Key(config('app.jwt_code_pc'),'HS256'));
            }else{
                failure(config('error.er14')['code'],config('error.er14')['msg']);
            }
        }catch (\Exception $e) {
            failure(config('error.er14')['code'],config('error.er14')['msg']);
        }
        
        return $next($request);
    }
}